<?php
//验证token
public class WXController : Controller
    {
        public static readonly string Token = "WXToken";//与微信公众账号服务器配置的Token设置保持一致，区分大小写。
        public static readonly string EncodingAESKey = "Q3vhz8zLwPYPbjz6S7JXiwSyAgW4vmInz6RzWWltEpk";//与微信公众账号服务器配置的EncodingAESKey设置保持一致，区分大小写。
        public static readonly string AppId = ".........";//与微信公众账号后台的AppId设置保持一致，区分大小写。(这里的AppId填写自己的)

        // GET: WC/WX
        public ActionResult Index()
        {
            return View();
        }

        [HttpGet]
        [ActionName("Index")]
        public Task<ActionResult> Get(string signature, string timestamp, string nonce, string echostr)
        {
            return Task.Factory.StartNew(() =>
            {
                if (CheckSignature.Check(signature, timestamp, nonce, Token))
                {
                    return echostr; //返回随机字符串则表示验证通过
                }
                else
                {
                    return "failed:" + signature + "," + CheckSignature.GetSignature(timestamp, nonce, Token) + "。" +
                           "当你打开URL访问当前地址的时候，说明该地址可以作为微信公众号服务器配置地址的URL，请注意保持Token一致。";
                }
            }).ContinueWith<ActionResult>(task => Content(task.Result));
        }    
    }